// miniprogram/pages/statistics/ranking.js
Page({
  data: {
    userInfo: {},
    sceneType: '',
    sceneTypeName: '',
    rankingList: [],
    currentUserRank: 0
  },

  onLoad() {
    const app = getApp()
    this.setData({
      userInfo: app.globalData.userInfo,
      sceneType: app.globalData.sceneType,
      sceneTypeName: app.getSceneTypeName(app.globalData.sceneType)
    })
    this.loadRankingData()
  },

  loadRankingData() {
    // 模拟排行榜数据
    const rankingList = [
      { id: 1, name: '张三', avatar: '/images/avatar.png', points: 1500, rank: 1 },
      { id: 2, name: '李四', avatar: '/images/avatar.png', points: 1450, rank: 2 },
      { id: 3, name: '王五', avatar: '/images/avatar.png', points: 1400, rank: 3 },
      { id: 4, name: '赵六', avatar: '/images/avatar.png', points: 1350, rank: 4 },
      { id: 5, name: '钱七', avatar: '/images/avatar.png', points: 1300, rank: 5 },
      { id: 6, name: '孙八', avatar: '/images/avatar.png', points: 1250, rank: 6 },
      { id: 7, name: '周九', avatar: '/images/avatar.png', points: 1200, rank: 7 }
    ]
    
    // 查找当前用户排名
    const currentUser = rankingList.find(user => user.id === this.data.userInfo.id)
    const currentUserRank = currentUser ? currentUser.rank : 0
    
    this.setData({ 
      rankingList,
      currentUserRank
    })
  },

  viewUserProfile(e) {
    const userId = e.currentTarget.dataset.userId
    // 模拟跳转到用户详情页面
    wx.showToast({
      title: '查看用户详情',
      icon: 'none'
    })
  }
})